package com.cn.longdistancebusstation.scenic;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;

import com.cn.longdistancebusstation.R;
import com.cn.longdistancebusstation.base.BaseActivity;
import com.cn.longdistancebusstation.fragment.OrderNoteFragment;
import com.cn.longdistancebusstation.fragment.ScenicIntroductionFragment;
import com.cn.longdistancebusstation.fragment.TrafficInfoFragment;

/**
 * Created by mucheng on 2018/3/29.
 */

public class ScenicIntroductionActivity extends BaseActivity implements View.OnClickListener{
    private Fragment mfragmentContent;
    private TextView mOrderNoteTextView;
    private TextView mScenicIntroduceTextView;
    private TextView mTrafficInfoTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scenic_introduction);
        getTitleTextView().setText("景点简介");
        initView();
    }

    private void initView() {
        mOrderNoteTextView=(TextView)findViewById(R.id.order_note);
        mOrderNoteTextView.setOnClickListener(this);
        mScenicIntroduceTextView=(TextView)findViewById(R.id.scenic_introduce);
        mScenicIntroduceTextView.setOnClickListener(this);
        mTrafficInfoTextView=(TextView)findViewById(R.id.traffic_info);
        mTrafficInfoTextView.setOnClickListener(this);
        // 设置默认显示预定须知界面
        if (mfragmentContent == null) {
            mfragmentContent = new OrderNoteFragment();
        }
        switchConent(mfragmentContent);
    }


    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.order_note:
                mfragmentContent = new OrderNoteFragment();
                resetAll();
                mOrderNoteTextView.setBackgroundResource(R.mipmap.scenic_pro_1_my);
                mOrderNoteTextView.setTextColor(getResources().getColor(R.color.white));
                break;
            case R.id.scenic_introduce:
                mfragmentContent=new ScenicIntroductionFragment();
                resetAll();
                mScenicIntroduceTextView.setBackgroundResource(R.mipmap.scenic_pro_1_my);
                mScenicIntroduceTextView.setTextColor(getResources().getColor(R.color.white));
                break;
            case R.id.traffic_info:
                mfragmentContent=new TrafficInfoFragment();
                resetAll();
                mTrafficInfoTextView.setBackgroundResource(R.mipmap.scenic_pro_1_my);
                mTrafficInfoTextView.setTextColor(getResources().getColor(R.color.white));
                break;
        }
        if (mfragmentContent != null) {
            switchConent(mfragmentContent);
        }

    }
    /**
     * 切换Fragment
     *
     * @param fragment
     */
    public void switchConent(Fragment fragment) {
        mfragmentContent = fragment;
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.scenic_frame_layout, mfragmentContent).commit();
    }


    /**
     * 将所有的Fragment隐藏
     * 将所有的图片设置为不选中
     */
    public void resetAll() {
        mOrderNoteTextView.setBackgroundResource(R.mipmap.scenic_pro_2_all);
        mOrderNoteTextView.setTextColor(getResources().getColor(R.color.themeColor));

        mScenicIntroduceTextView.setBackgroundResource(R.mipmap.scenic_pro_2_all);
        mScenicIntroduceTextView.setTextColor(getResources().getColor(R.color.themeColor));

        mTrafficInfoTextView.setBackgroundResource(R.mipmap.scenic_pro_2_all);
        mTrafficInfoTextView.setTextColor(getResources().getColor(R.color.themeColor));
    }
}
